package co.yixiang.yshop.module.product.dal.mysql.productcoupon;

import co.yixiang.yshop.framework.mybatis.core.mapper.BaseMapperX;
import co.yixiang.yshop.module.product.controller.admin.productcoupon.vo.ProductCouponIssueRecordRespVO;
import co.yixiang.yshop.module.product.dal.dataobject.productcoupon.ProductCouponCdKeyDO;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.poi.ss.formula.functions.T;

import java.util.List;

/**
 * 商品优惠券 Mapper
 *
 * @author moxiangrong
 */
@Mapper
public interface ProductCouponCdkeyMapper extends BaseMapperX<ProductCouponCdKeyDO> {

    @Select("select t1.*,t2.is_used ,t2.receive_time,t2.usage_time,t3.username from \n" +
            "(select id,coupon_id,code,status from \n" +
            "   yshop_store_product_coupon_cdkey yspcc ${ew.customSqlSegment}) t1\n" +
            "left join yshop_store_product_coupon_relation t2 \n" +
            "on t1.id=t2.cd_key_id \n" +
            "left join yshop_user t3 \n" +
            "on t2.uid=t3.id")
    List<ProductCouponIssueRecordRespVO> record(IPage<ProductCouponIssueRecordRespVO> mpPage,
                                                @Param(Constants.WRAPPER) QueryWrapper<ProductCouponCdKeyDO> wrapper);


}
